﻿namespace AC.ExtendedRenderer.Toolkit
{
    using ComponentFactory.Krypton.Toolkit;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    [Description("Displays an editable textbox with a drop-down list of permitted values."), ComVisible(true), ClassInterface(ClassInterfaceType.AutoDispatch), ToolboxItem(true), ToolboxBitmap(typeof(AC.ExtendedRenderer.Toolkit.KryptonComboBox), "ToolboxBitmaps.KryptonComboBox.bmp"), DefaultEvent("SelectedIndexChanged"), DefaultProperty("Text"), DefaultBindingProperty("Text"), LookupBindingProperties("DataSource", "DisplayMember", "ValueMember", "SelectedValue"), DesignerCategory("code")]
    public class KryptonImageComboBox : ComponentFactory.Krypton.Toolkit.KryptonComboBox
    {
        public KryptonImageComboBox()
        {
            base.ComboBox.DrawItem += new DrawItemEventHandler(this.OnDrawItem);
        }

        protected void OnDrawItem(object sender, DrawItemEventArgs e)
        {
            if ((e.Index >= 0) && (((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit) && (base.Items[e.Index] is KryptonListItem)))
            {
                e.DrawBackground();
                Color foreColor = base.ComboBox.ForeColor;
                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                    foreColor = SystemColors.HighlightText;
                }
                Color backColor = base.ComboBox.BackColor;
                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                    backColor = SystemColors.Highlight;
                }
                Image image = ((KryptonListItem) base.Items[e.Index]).Image;
                Rectangle bounds = new Rectangle(e.Bounds.X + 0x13, e.Bounds.Y, e.Bounds.Width - 0x13, e.Bounds.Height);
                bounds = bounds;
                if (e.Index >= 0)
                {
                    e.Graphics.TextRenderingHint = CommonHelper.PaletteTextHintToRenderingHint(base.StateNormal.ComboBox.PaletteContent.GetContentShortTextHint(PaletteState.Normal));
                    TextRenderer.DrawText(e.Graphics, base.ComboBox.Text, base.ComboBox.Font, bounds, foreColor, backColor, TextFormatFlags.NoPadding | TextFormatFlags.TextBoxControl);
                    if (image != null)
                    {
                        e.Graphics.DrawImage(image, new Rectangle(3, 3, 0x10, 0x10));
                    }
                }
            }
        }
    }
}

